<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateInventoryAllot extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('inventory_allot')) {
            Schema::create('inventory_allot', function (Blueprint $table) {
                $table->id();
                $table->string('number')->default('')->default('')->comment('调拨编号');
                $table->unsignedInteger('source_warehouse_id')->default(0)->comment('原仓库ID');
                $table->unsignedInteger('target_warehouse_id')->default(0)->comment('目标仓库ID');
                $table->unsignedInteger('target_user_id')->default(0)->comment('目标用户ID');
                $table->string('description')->default('')->comment('说明');
                $table->string('status')->default('')->comment('状态');
                $table->string('type')->default('')->comment('类型');
                $table->unsignedInteger('create_user_id')->default(0)->comment('创建人ID');
                $table->unsignedInteger('audit_user_id')->default(0)->comment('审核人ID');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }

        if (!Schema::hasTable('inventory_allot_items')) {
            Schema::create('inventory_allot_items', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('inventory_allot_id')->default(0)->comment('调拨ID');
                $table->unsignedInteger('inventory_id')->default(0)->comment('备件库ID');
                $table->unsignedInteger('quantity')->default(0)->comment('申请调拨数量');
                $table->unsignedInteger('action_quantity')->default(0)->comment('办理数量');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('inventory_allot');
        Schema::dropIfExists('inventory_allot_items');
    }
}
